package com.speed.service;

import java.util.List;

import com.speed.entity.SeatInfo;

public class SeatService {

	public SeatInfo findSeatInfoByActiviterID(Long id) {
		SeatInfo seatInfo = SeatInfo.MODEL_DAO
				.findFirst("select * from " + SeatInfo.TABLE_NAME + " where " + SeatInfo.ACTIVITER_ID + " = ? ", id);
		return seatInfo;
	}

	public void saveOrUpdateSeatInfo(SeatInfo seatInfo) {
		SeatInfo findSeatInfo = SeatInfo.MODEL_DAO.findById(seatInfo.get(SeatInfo.ID));
		// save
		SeatInfo seatInfo2 = new SeatInfo();
		seatInfo2.put(seatInfo);
		if (findSeatInfo == null) {
			seatInfo2.save();

			// update
		} else {
			seatInfo2.update();
		}
	}

	/**
	 * 修改SeatInfo对象 还未决定如何传参
	 */
	public void updateSeatInfo(String id) {
		SeatInfo seatInfo = SeatInfo.MODEL_DAO.findById(id);
		seatInfo.update();
	}

	/**
	 * 删除SeatInfo对象,标识未确定
	 */
	public void delSeatInfo(String id) {
		SeatInfo.MODEL_DAO.findById(id).set("isDel", 1).update();
	}

	/**
	 * 查询SeatInfo对象
	 */
	public SeatInfo findById(String id) {
		return SeatInfo.MODEL_DAO.findById(id);
	}

	/**
	 * 查询已经有座位的活动者
	 */
	public List<SeatInfo> findActivitersHasSeat(Integer activtitesID) {
		return SeatInfo.MODEL_DAO.find("SELECT " + SeatInfo.ACTIVITER_ID + " FROM " + SeatInfo.TABLE_NAME + " WHERE "
				+ SeatInfo.ACTIVITER_ID + " <> '' AND " + SeatInfo.ACTIVITES_ID + " = ? ", activtitesID);
	}

}
